package com.lxj.fast_android_demo.ui.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.lxj.fast_android_demo.R;
import com.lxj.fast_android_demo.ui.adapter.holder.TableHolder;
import com.lxj.fast_android_demo.util.ViewUtil;

public class TableAdapter extends BaseAdapter {
	private ArrayList<HashMap<String, Object>> dataList;

	public TableAdapter(ArrayList<HashMap<String, Object>> dataList) {
		this.dataList = dataList;
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public HashMap<String, Object> getItem(int arg0) {
		return dataList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		TableHolder holder = null;
		if (null == arg1) {
			arg1 = ViewUtil.buildView(R.layout.table_row);
			holder = new TableHolder(arg1);
		} else {
			holder = (TableHolder) arg1.getTag();
		}
		HashMap<String, Object> domain = getItem(arg0);
		holder.fillData(arg0, domain, arg1);
		return arg1;
	}

}
